#!/usr/bin/env python
"""

"""
import os

PROMPT_CONFIG = {
    "v1": {
        "form": {
            "ask_for_leave_form": {
                "name": "ask_for_leave_form",
                "type": "form",
                "description": "涉及请假相关操作",
                "file": "ask_for_leave_form.md",
            },
        },
        "natural": {
            "ask_for_leave": {
                "name": "ask_for_leave",
                "type": "natural",
                "description": "涉及请假相关操作",
                "file": "ask_for_leave.md",
            },
        }
    },
}


class Prompt:
    def __init__(self, version: str):
        self.version = version

    def get_prompt_list(self, type: str = "form"):
        if self.version not in PROMPT_CONFIG:
            raise Exception(f"不支持的版本：{self.version}")
        if type not in PROMPT_CONFIG[self.version]:
            raise Exception(f"不支持的 prompt 类型：{type}")
        return PROMPT_CONFIG[self.version][type]

    def get_prompt(self, type: str = "form", name: str = None):
        if self.version not in PROMPT_CONFIG:
            raise Exception(f"不支持的版本：{self.version}")
        if type not in PROMPT_CONFIG[self.version]:
            raise Exception(f"不支持的 prompt 类型：{type}")
        if name not in PROMPT_CONFIG[self.version][type]:
            raise Exception(f"不支持的 prompt 名称：{name}")

        prompt_config = PROMPT_CONFIG[self.version][type][name]

        # 生成prompt本地文件读取目录，目录地址为markdown/版本号/prompt名称.md
        prompt_file_path = os.path.join(os.path.dirname(__file__), "markdown", self.version, f"{prompt_config['file']}")

        # 判断文件是否存在
        if not os.path.exists(prompt_file_path):
            raise Exception(f"prompt 文件不存在：{prompt_file_path}")

        with open(prompt_file_path, "r", encoding="utf-8") as f:
            prompt_content = f.read()

        return prompt_content
